<template>
	<view class="sxran-im-content chat-page" :class="[$Im.getTheme()]">
		
		<sxran-im-chat></sxran-im-chat>
	</view>
</template>

<script>
	export default {
		async onLoad(query) {
			const {
				id
			} = query;
			uni.$Im.setCurrentConversationId(id);
			//获取会话数据
			const conversation = await uni.$Im.getConversationCmdMethods();
			//第一次需要生成会话
			if(!conversation){
				const params = {
					"chatType": 1,
					"originalTo": id.split(':')[1]
				}
				uni.$Im.generateConversationId(params, (data) => {
				})
				return;
			}
			//获取聊天记录
			uni.$Im.getConversationByIdMessageList({
				"conversation": id,
				"maxTime": Date.now(),
				"offset": 1,
				"count": 20,
			}, (data) => {
				uni.$Im.clearCurrentConversationUnreadCount(id)
			})
		},
	}
</script>

<style scoped lang="scss">
	.chat-page {
		background-color: var(--uni-bg-color);
		height: 100vh;
		overflow: hidden;
	}
</style>